<?php
include_once('admin-load.php');
    $query = "SELECT * FROM clients";
    $clients = $dbna->get_results($query);
    //print_r($users)
   if (isset($_GET['action']) && $_GET['action'] == 'delete') {
       $client_id = $_GET['client_id'];
       if (isset($_GET['confirm']) && $_GET['confirm']==1) {
           delete_clients($client_id);
       }
       $msg = 'Do you want to delete clients? <a href="client.php?action=delete&client_id='.$client_id.'&confirm=1">YES</a> <a href="client.php">NO</a>';
   }
?>
<?php
	include_once 'header.php';
?>
            <div id="main_content">
                            <div id="content">
                    
		</div>
        <div class="container">
            <h5>clients list</h5>

        </div>
				<div id="main">
                    <h2>clients list</h2>
                    <?php
                        if (isset($msg)) {
                            echo '<div class="warning">'. $msg . '</div>';
                        }
                    ?>
                    <table>
                        <thead>
                            <tr>
                                <th>company name</th>
                                <th>address</th>
                                <th>phone</th>
                                <th>fax</th>
                                <th>country</th>
                                <th>zip code</th>
                                 <th>client</th>
                            </tr>
                        </thead>
                        <tbody>
                           <?php
                                if (!empty ($clients)) {
                                    foreach($clients as $c) {
                                         $edit = '<a href="client-edit.php?client_id='.$c->id.'"> Edit</a>';
                                         $delete = '<a href="client.php?action=delete&client_id='.$c->id.'">Delete</a>';
                                        printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
                                                $c->company_name , $c->address, $c->phone, $c->fax, $c->country, $c->zip_code, $edit. ' '.$delete
                                               );
                                    }
                                }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
<?php 
	include_once 'footer.php';
?>